package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.puti.common.core.domain.R;
import com.puti.doctor.domain.vo.BillVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;
import com.puti.doctor.domain.DoctorBill;
import com.puti.doctor.service.IDoctorBillService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 医生-流水 医生-流水Controller
 * 
 * @author puti
 * @date 2021-04-22
 */
@CrossOrigin
@RestController
@RequestMapping("/bill")
public class DoctorBillController extends BaseController
{
    @Autowired
    private IDoctorBillService doctorBillService;

    /**
     * 查询医生-流水 医生-流水列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DoctorBill doctorBill)
    {
        startPage();
        List<DoctorBill> list = doctorBillService.selectDoctorBillList(doctorBill);
        return getDataTable(list);
    }

    /**
     * 导出医生-流水 医生-流水列表
     */
    @Log(title = "医生-流水 医生-流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorBill doctorBill) throws IOException
    {
        List<DoctorBill> list = doctorBillService.selectDoctorBillList(doctorBill);
        ExcelUtil<DoctorBill> util = new ExcelUtil<DoctorBill>(DoctorBill.class);
        util.exportExcel(response, list, "医生-流水 医生-流水数据");
    }

    /**
     * 获取医生-流水 医生-流水详细信息
     */
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") String billId)
    {
        return AjaxResult.success(doctorBillService.selectDoctorBillById(billId));
    }

    /**
     * 新增医生-流水 医生-流水
     */
    @Log(title = "医生-流水 医生-流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorBill doctorBill)
    {
        return toAjax(doctorBillService.insertDoctorBill(doctorBill));
    }

    /**
     * 修改医生-流水 医生-流水
     */
    @Log(title = "医生-流水 医生-流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorBill doctorBill)
    {
        return toAjax(doctorBillService.updateDoctorBill(doctorBill));
    }

    /**
     * 删除医生-流水 医生-流水
     */
    @Log(title = "医生-流水 医生-流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable String[] billIds)
    {
        return toAjax(doctorBillService.deleteDoctorBillByIds(billIds));
    }
    //订单流水，列表分页展示
    @GetMapping("/findDoctorId/{doctorId}")
    public R findDoctorId(@PathVariable("doctorId") Long doctorId,
                          @RequestParam("judge") int judge,
                          @RequestParam("startTime") String startTime,
                          @RequestParam("endTime") String endTime,
                          @RequestParam("page") int page,
                          @RequestParam("pageSize") int pageSize) {
        return R.ok(doctorBillService.findDoctorId(doctorId,judge,startTime,endTime,page,pageSize),"查询成功");
    }
    //医生的收入和支出
    @GetMapping("/findByDoctorId/{doctorId}")
    public R findByDoctorId(@PathVariable("doctorId") Long doctorId){
        List<BillVo> byDoctorId = doctorBillService.findByDoctorId(doctorId);
        if(byDoctorId!=null){
            return R.ok(byDoctorId,"查询成功!");
        }else {
            return R.fail("暂无记录!");
        }
    }
}
